<?php
/**
 * Created by PhpStorm.
 * User: tanghui
 * Date: 2017/7/10
 * Time: 上午9:06
 */

class Controller_Seller_User extends Controller_Seller_Abstract{

    private $DB_SERVER = "xhs_slave";
    /*
     * 个人中心
     */
    public function myCenterAction(){
        global $_F;
        $uid = $_F['uid'];
        $where = array();
        $where['c.uid'] = $uid;
        $clerkTable = new FTable("clerk", "c", $this->DB_SERVER);
        $data = $clerkTable->fields("c.uid, c.avatar, c.shop_id, c.gender, c.nickname, c.openid, cs.name as shop_name
        , cs.work_status as shop_work_status, cs.address as shop_address, cs.manager as shop_manager")
            ->leftJoin("chain_shop", "cs", "cs.id=c.shop_id")
            ->where($where)
            ->find();
        $this->assign("data", $data);
        $this->assign("s_url", $_F['s_url']);
        $this->display("about");
    }

    /*
     * 修改连锁店状态
     */
    public function modifyChainStatusAction(){
        $id = FRequest::getPostInt("id");
        $status = FRequest::getPostInt("status");
//        var_dump($status);exit();
        $ret = Service_User::chainStatusModifyAction($id, $status);
        FResponse::output($ret);
    }

    /*
     * 资金管理
     */
    public function fundAction(){
        global $_F;
//        $this->openDebug();
        $shop_id = $_F['shop_id'];
        $data = Service_User::incomeTjAction($shop_id);
        $this->assign("data", $data);
        $this->display("manage");
    }



    /*
     * 当天收入明细
     */
    public function incomeDetailTodayAction(){
        global $_F;
//        $this->openDebug();
        $shop_id = $_F['shop_id'];
        $page = FRequest::getInt("page") ? FRequest::getInt("page"):1;
        //当天的收入
        $start_time = date("Y-m-d", time()) . " 00:00:00";
        $end_time = date("Y-m-d", time()) . " 23:59:59";
        $where["pay_time"] = array("lte" => $end_time, "gte" => $start_time);
        $Data = Service_User::incomeDetailAction($shop_id, $start_time, $end_time, $page);
        $this->assign("data", $Data);
        $this->display("income-today");
    }

    /*
     * 周收入明细
     */
    public function incomeDetailWeekAction(){
        global $_F;
//        $this->openDebug();
        $page = FRequest::getInt("page") ? FRequest::getInt("page"):1;
        //本周收入
        $shop_id = $_F['shop_id'];
        $start_time = date("Y-m-d", strtotime("-6 days")) . " 00:00:00";
        $end_time = date("Y-m-d", time()) . " 23:59:59";
        $where["pay_time"] = array("lte" => $end_time, "gte" => $start_time);
        $Data = Service_User::incomeDetailAction($shop_id, $start_time, $end_time, $page);
        $this->assign("data", $Data);
        $this->display("income-week");
    }

    /*
     * 月收入明细
     */
    public function incomeDetailMonthAction(){
        global $_F;
//        $this->openDebug();
        $page = FRequest::getInt("page") ? FRequest::getInt("page"):1;
        $shop_id = $_F['shop_id'];
        //本月收入
        $start_time = date("Y-m-d", strtotime("-29 days")) . " 00:00:00";
        $end_time = date("Y-m-d", time()) . " 23:59:59";
        $where["pay_time"] = array("lte" => $end_time, "gte" => $start_time);
        $Data = Service_User::incomeDetailAction($shop_id, $start_time, $end_time, $page);
        $this->assign("data", $Data);
        $this->display("income-month");
    }

    /*
    * 所有收入明细
    */
    public function incomeDetailAllAction(){
        global $_F;
//        $this->openDebug();
        $page = FRequest::getInt("page") ? FRequest::getInt("page"):1;
        $shop_id = $_F['shop_id'];
        //本月收入
        $Data = Service_User::incomeDetailAction($shop_id, "", "", $page);
        $this->assign("data", $Data);
        $this->display("income-all");
    }


    /*
     * 订单统计
     */
    public function orderTjAction(){
        global $_F;
//        $this->openDebug();
        $shop_id = $_F['shop_id'];
        $data = Service_User::orderTjAction($shop_id);
        $this->assign("data", $data);
        $this->display("orders-tj");
    }


}